using JuMP, GLPK

# 准备一个优化模型
m = Model(with_optimizer(GLPK.Optimizer))
# m = Model(with_optimizer(Gurobi.Optimizer))
# m = Model(with_optimizer(CPLEX.Optimizer))

# 声明变量
@variable(m, 0 <= x1 <= 10)
@variable(m, x2 >= 0)
@variable(m, x3 >= 0)

# 目标函数
@objective(m, Max, x1 + 2x2 + 5x3)

# 设置约束
@constraint(m, constant1, -x1 + x2 + 3x3 <= -5)
@constraint(m, constant2, x1 + 3x2 - 7x3 <= 10)

# 输出模型
print(m)

# 求解模型
JuMP.optimize!(m)

# 输出最优解
println("最优解：")
println("x1 = ", JuMP.value(x1))
println("x2 = ", JuMP.value(x2))
println("x3 = ", JuMP.value(x3))

# 输出对偶问题的解
println("对偶变量：")
println("dual1 = ", JuMP.shadow_price(constant1))
println("dual2 = ", JuMP.shadow_price(constant2))